<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\Plugin\ContactMessageBatchSend\Action\Workbench;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use MoChat\App\Common\Middleware\WorkbenchAuthMiddleware;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Request\ValidateSceneTrait;
use MoChat\Plugin\ContactMessageBatchSend\Action\Workbench\Traits\ContactTrait;

/**
 * 客户消息群发 - 筛选客户.
 * @Controller
 */
class FilterContact extends AbstractAction
{
    use ValidateSceneTrait;
    use ContactTrait;

    /**
     * @Middlewares({
     *     @Middleware(WorkbenchAuthMiddleware::class)
     * })
     * @RequestMapping(path="/workbench/contactMessageBatchSend/filterContact", methods="put")
     */
    public function handle(): array
    {
        # # 参数验证
        $this->validated($this->request->all());

        # # 接收参数
        $params = [
            'employeeIds' => $this->request->input('employeeIds'),
            'addTimeStart' => $this->request->input('addTimeStart', ''),
            'addTimeEnd' => $this->request->input('addTimeEnd', ''),
            'followUpStatusIds' => $this->request->input('followUpStatusIds'),
            'tagsType' => $this->request->input('tagsType'),
            'tags' => $this->request->input('tags'),
            'removeTags' => $this->request->input('removeTags'),
        ];
        $contactIds = $this->filterContact($params);

        return [count($contactIds)];
    }

    /**
     * 验证规则.
     *
     * @return array 响应数据
     */
    protected function rules(): array
    {
        return [
            'employeeIds' => 'required|array',
        ];
    }

    /**
     * 验证错误提示.
     * @return array 响应数据
     */
    protected function messages(): array
    {
        return [
            'employeeIds.required' => '员工id 必填',
            'status.array' => '员工id 格式错误: 必须为数',
        ];
    }
}
